package com.lhwl.it.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LoginFilter implements Filter{
	private Log log = LogFactory.getLog(this.getClass());
	
	
	@Override
	public void init(FilterConfig filterconfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest servletrequest,
			ServletResponse servletresponse, FilterChain filterchain)
			throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)servletrequest;
		HttpServletResponse resp=(HttpServletResponse)servletresponse;
		String url=req.getRequestURL().toString();
		if(url.indexOf("itmanager")!=-1){
			RequestDispatcher dispather = servletrequest.getRequestDispatcher("/timeout.jsp");
			HttpSession session=req.getSession();
			Object obj=session.getAttribute("yh");
			if(obj!=null){
				filterchain.doFilter(req, resp);
			}else{
				dispather.forward(req, resp);
			}
		}else{
			filterchain.doFilter(req, resp);
		}
	}

	@Override
	public void destroy() {
		
	}

}
